<!--vue模板-->
<template>
  <!--树形下拉列表-->
  <el-tree-select v-model="deptId" :props="defaultProps"  :data="data" :render-after-expand="false" @current-change="chg"/>
</template>

<!--vue 组件选项定义-->
<script>
export default {
  data() {
    return {
      data: [],
      defaultProps: {
        children: "childs",
        label: "name",
        value:"id"
      }
    };
  },
  props:{
    deptId:{
        type:String,
        default:""
    }
  },
  $emit:["update:deptId"],
  created(){
    this.queryTree();
  },
  methods: {
    chg(node){
        //更新父组件 对应当前属性deptId的值 
        this.$emit("update:deptId",node.id);
    },
    queryTree() {
      this.$http.get("/api/dept/allchild", { pid: "0" }).then((res) => {
        if (res.code == 200) {
            let tmp={
                name:"公司",
                id:"0"
            };
            tmp['childs']=res.result;
            console.log(tmp);
          this.data = [tmp];
        }
      });
    },
  },
};
</script>

<!--vue样式 scoped当前样式只适用于当前组件-->
<style scoped></style>
